﻿using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;

namespace MiddleWare
{
    public class Middleware2
    {
        private readonly RequestDelegate _next;
        public Middleware2(RequestDelegate next)
        {
            _next = next;
        }
        public Task InvokeAsync(HttpContext context)
        {
            if (!context.Items.ContainsKey("M_test"))
            {
                context.Items.Add("M_test", "");
            }
            context.Items["M_test"] = $"{context.Items["M_test"]} Middleware2 ";
            return this._next(context);
        }
    }
    //增加一个
    public static class UseMiddleware2Extensions
    {
        public static IApplicationBuilder UseMiddleware2(this IApplicationBuilder builder)
        {
            return builder.UseMiddleware<Middleware2>();
        }
    }
}
